package traveldream.ejb.entities;

import java.io.Serializable;
import java.util.List;

import javax.persistence.*;

import traveldream.ejb.DTO.HotelDTO;


/**
 * The persistent class for the hotel database table.
 * 
 */
@Entity
@Table(name="HOTEL")
@NamedQueries({
@NamedQuery(name="Hotel.findAll", query="SELECT h FROM Hotel h WHERE h.Invalid=false"),
@NamedQuery(name="Hotel.findNotBooked", query="SELECT h FROM Hotel h WHERE h.Invalid=false AND h.city = :citySelected AND h NOT IN (SELECT b.hotel FROM Booking b WHERE b.departure_Date <= :arr_date AND b.arrival_Date >= :dep_date)")
})
public class Hotel implements Serializable {
	private static final long serialVersionUID = 1L;
	
	public static final String FIND_ALL = "Hotel.findAll";
	
	@Id
	@GeneratedValue( strategy = GenerationType.IDENTITY )
	private int id;

	private String address;

	@Column(name="`Available Places`")
	private int available_Places;

	private String city;

	private String description;

	private String EMail;

	private String name;

	private String phone;

	private int price;

	private int stars;

	private String website;
	
	@OneToMany(mappedBy="hotel")
	private List<DefaultPackage> defaultPackages;
	

	@OneToMany(mappedBy="hotel")
	private List<Booking> bookings;
	
	@OneToMany(mappedBy="hotel")
	private List<CustomizedPackage> customPackages;
	
	@OneToMany(mappedBy="Hotel")
	private List<GiftList> giftedHotel;
	
	
	public List<GiftList> getGiftedHotel() {
		return giftedHotel;
	}

	public void setGiftedHotel(List<GiftList> giftedHotel) {
		this.giftedHotel = giftedHotel;
	}

	public List<CustomizedPackage> getCustomPackages() {
		return customPackages;
	}

	public void setCustomPackages(List<CustomizedPackage> customPackages) {
		this.customPackages = customPackages;
	}

	public List<Booking> getBookings() {
		return bookings;
	}

	public void setBookings(List<Booking> bookings) {
		this.bookings = bookings;
	}

	public List<DefaultPackage> getDefaultPackages() {
		return defaultPackages;
	}

	public void setDefaultPackages(List<DefaultPackage> defaultPackages) {
		this.defaultPackages = defaultPackages;
	}

	private boolean Invalid;

	public boolean isInvalid() {
		return Invalid;
	}

	public void setInvalid(boolean invalid) {
		Invalid = invalid;
	}
	
	public Hotel() {
	}
	
	public Hotel(HotelDTO hDTO){
		//id = hDTO.getId();
		address = hDTO.getAddress();
		available_Places = hDTO.getAvailablePlaces();
		city = hDTO.getCity();
		description = hDTO.getDescription();
		EMail = hDTO.getEmail();
		name = hDTO.getName();
		phone = hDTO.getPhone();
		price = hDTO.getPrice();
		stars = hDTO.getStars();
		website = hDTO.getWebsite();
		this.Invalid=false;
	}
	
	public HotelDTO convertToDTO(){
    	HotelDTO hDTO = new HotelDTO();
    	hDTO.setId(id);
    	hDTO.setName(name);
    	hDTO.setAvailablePlaces(available_Places);
    	hDTO.setDescription(description);
    	hDTO.setWebsite(website);
    	hDTO.setEmail(EMail);
    	hDTO.setCity(city);
    	hDTO.setStars(stars);
    	hDTO.setAddress(address);
    	hDTO.setPhone(phone);
    	hDTO.setPrice(price);
    	return hDTO;
    }

	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getAddress() {
		return this.address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public int getAvailable_Places() {
		return this.available_Places;
	}

	public void setAvailable_Places(int available_Places) {
		this.available_Places = available_Places;
	}

	public String getCity() {
		return this.city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getEMail() {
		return this.EMail;
	}

	public void setEMail(String EMail) {
		this.EMail = EMail;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPhone() {
		return this.phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public int getPrice() {
		return this.price;
	}

	public void setPrice(int price) {
		this.price = price;
	}

	public int getStars() {
		return this.stars;
	}

	public void setStars(int stars) {
		this.stars = stars;
	}

	public String getWebsite() {
		return this.website;
	}

	public void setWebsite(String website) {
		this.website = website;
	}

}